/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

/*
 * PromotionDialog.java
 *
 * Created on Feb 26, 2011, 11:26:34 AM
 */
package form;

/**
 *
 * @author hz
 */
public class PromotionDialog extends javax.swing.JDialog {

    /** Creates new form PromotionDialog */
    public PromotionDialog(java.awt.Frame parent, boolean modal, boolean isWhite) {
        super(parent, modal);
        initComponents();
        if (!isWhite) {
            queen.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/bq.png")));
            rook.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/br.png")));
            bishop.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/bb.png")));
            knight.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/bn.png")));
        }
    }

    /** This method is called from within the constructor to
     * initialize the form.
     * WARNING: Do NOT modify this code. The content of this method is
     * always regenerated by the Form Editor.
     */
    @SuppressWarnings("unchecked")
    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
    private void initComponents() {

        queenPanel = new javax.swing.JPanel();
        queen = new javax.swing.JLabel();
        rookPanel = new javax.swing.JPanel();
        rook = new javax.swing.JLabel();
        bishopPanel = new javax.swing.JPanel();
        bishop = new javax.swing.JLabel();
        knightPanel = new javax.swing.JPanel();
        knight = new javax.swing.JLabel();

        setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
        getContentPane().setLayout(new java.awt.GridLayout());

        queenPanel.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        queenPanel.setName("queenPanel"); // NOI18N
        queenPanel.setOpaque(false);
        queenPanel.setPreferredSize(new java.awt.Dimension(44, 44));
        queenPanel.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                queenPanelMouseClicked(evt);
            }
        });
        queenPanel.setLayout(null);

        queen.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/wq.png"))); // NOI18N
        queen.setName("queen"); // NOI18N
        queenPanel.add(queen);
        queen.setBounds(5, 5, 36, 36);

        getContentPane().add(queenPanel);

        rookPanel.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        rookPanel.setName("rookPanel"); // NOI18N
        rookPanel.setOpaque(false);
        rookPanel.setPreferredSize(new java.awt.Dimension(44, 44));
        rookPanel.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                rookPanelMouseClicked(evt);
            }
        });
        rookPanel.setLayout(null);

        rook.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/wr.png"))); // NOI18N
        rook.setName("rook"); // NOI18N
        rookPanel.add(rook);
        rook.setBounds(5, 5, 36, 36);

        getContentPane().add(rookPanel);

        bishopPanel.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        bishopPanel.setName("bishopPanel"); // NOI18N
        bishopPanel.setOpaque(false);
        bishopPanel.setPreferredSize(new java.awt.Dimension(44, 44));
        bishopPanel.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                bishopPanelMouseClicked(evt);
            }
        });
        bishopPanel.setLayout(null);

        bishop.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/wb.png"))); // NOI18N
        bishop.setName("bishop"); // NOI18N
        bishopPanel.add(bishop);
        bishop.setBounds(5, 5, 36, 36);

        getContentPane().add(bishopPanel);

        knightPanel.setBorder(javax.swing.BorderFactory.createLineBorder(new java.awt.Color(0, 0, 0)));
        knightPanel.setName("knightPanel"); // NOI18N
        knightPanel.setOpaque(false);
        knightPanel.setPreferredSize(new java.awt.Dimension(44, 44));
        knightPanel.addMouseListener(new java.awt.event.MouseAdapter() {
            public void mouseClicked(java.awt.event.MouseEvent evt) {
                knightPanelMouseClicked(evt);
            }
        });
        knightPanel.setLayout(null);

        knight.setIcon(new javax.swing.ImageIcon(getClass().getResource("/resources/wn.png"))); // NOI18N
        knight.setName("knight"); // NOI18N
        knightPanel.add(knight);
        knight.setBounds(5, 5, 36, 36);

        getContentPane().add(knightPanel);

        pack();
    }// </editor-fold>//GEN-END:initComponents

    private void queenPanelMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_queenPanelMouseClicked
        promotionType = 1;
        this.setVisible(false);
}//GEN-LAST:event_queenPanelMouseClicked

    private void rookPanelMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_rookPanelMouseClicked
        promotionType = 2;
        this.setVisible(false);
    }//GEN-LAST:event_rookPanelMouseClicked

    private void bishopPanelMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_bishopPanelMouseClicked
        promotionType = 3;
        this.setVisible(false);
    }//GEN-LAST:event_bishopPanelMouseClicked

    private void knightPanelMouseClicked(java.awt.event.MouseEvent evt) {//GEN-FIRST:event_knightPanelMouseClicked
        promotionType = 4;
        this.setVisible(false);
    }//GEN-LAST:event_knightPanelMouseClicked

    /**
     * @param args the command line arguments
     */
    public static void main(String args[]) {
        java.awt.EventQueue.invokeLater(new Runnable() {

            public void run() {
                PromotionDialog dialog = new PromotionDialog(new javax.swing.JFrame(), true, true);
                dialog.addWindowListener(new java.awt.event.WindowAdapter() {

                    public void windowClosing(java.awt.event.WindowEvent e) {
                        System.exit(0);
                    }
                });
                dialog.setVisible(true);
            }
        });
    }
    // Variables declaration - do not modify//GEN-BEGIN:variables
    private javax.swing.JLabel bishop;
    private javax.swing.JPanel bishopPanel;
    private javax.swing.JLabel knight;
    private javax.swing.JPanel knightPanel;
    private javax.swing.JLabel queen;
    private javax.swing.JPanel queenPanel;
    private javax.swing.JLabel rook;
    private javax.swing.JPanel rookPanel;
    // End of variables declaration//GEN-END:variables
    public int promotionType;
}
